package com.bing.test;

import com.bing.bean.Son;
import com.bing.bean.TestBean;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

/**
 * Created by kaibb on 15-9-5.
 */
public class HelloSrping {
    private BeanFactory beanFactory;


    private Son[] sons = {new Son(),new Son()};

    @Before
    public void before() {
        beanFactory = new XmlBeanFactory(new ClassPathResource("conf/helloSpring.xml"));
    }

    @Test
    public void helloSpring() {
        TestBean bean = beanFactory.getBean(TestBean.class);
        Assert.assertEquals("kaibing", bean.getName());
    }

    /**
     *
     */
    @Test
    public void testReplaceMethod() {
        TestBean bean = beanFactory.getBean(TestBean.class);

        String x = bean.replaceMethod();
        System.out.println(x);
        Assert.assertTrue(x.contains("成功"));
    }

    @Test
    public void helloAlias() {
        TestBean bean = (TestBean) beanFactory.getBean("bing");
        Assert.assertEquals("kaibing", bean.getName());
    }

    @Test
    public void helloFactoryBean() {
        TestBean bean = (TestBean) beanFactory.getBean("testFactory");
        Assert.assertEquals("hello FactoryBean", bean.getName());
    }

    @Test
    public void testBeanPostProcess() {

    }
}
